# Contributor: Sam L. Yes <samlukeyes123 at gmail dot com>
# Contributor: Andre Klitzing <aklitzing () gmail () com>

pkgname=msitools
pkgver=0.103
pkgrel=1
pkgdesc='Set of programs to inspect and build Windows Installer (.MSI) files'
arch=('loong64' 'x86_64')
url='https://wiki.gnome.org/msitools'
license=('LGPL' 'GPL')
depends=('libgsf' 'gcab' 'libxml2')
makedepends=('git' 'intltool' 'vala' 'meson' 'gobject-introspection' 'bash-bats')
provides=('libmsi-1.0.so')
_commit=4f36db7ba241fc8503fa85039b6d34280b126764  # tags/v0.103^0
source=(
  "$pkgname::git+https://gitlab.gnome.org/GNOME/msitools.git#commit=$_commit"
  'skip-failing-test.patch'
  'remove-git-dirty-suffix.patch'
  'use-system-bats.patch'
)
b2sums=('SKIP'
        '7c688138af873eed0bb1ddefe2910d9bdedb9174cc38464685c4c3c84f0c07b8aaa687093e694a4fafb952c1c010fbc7f0d62f69104d4557f13b9124f93d4209'
        'c30a2302e8cd202ecd084aa3d371d73021bc4fa5af4f3591f70362a1be41c738cf148a552f46f729bd8fade3d0b81a57eafbfa9d1c980e2ab5eed6f57f65a0ac'
        '1b24539e489d0be894d0a9e59cb4d91bda3f4ece566d015cfbdb4fb32cfd2f91845caf1787312cb7ca010942d10f61e91b44957da1f50184205f58e5a954b342')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//;s/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd "$pkgname"

  # skip failing test
  git apply -3 "$srcdir/skip-failing-test.patch"

  # remove -dirty suffix from pkgver
  git apply -3 "$srcdir/remove-git-dirty-suffix.patch"

  # use system bats (bash-bats)
  git apply -3 "$srcdir/use-system-bats.patch"
}

build() {
  arch-meson "$pkgname" build
  meson compile -C build
}

check() {
  meson test -C build --print-errorlogs
}

package() {
  meson install -C build --destdir "$pkgdir"

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" "$pkgname/copyright"
}
